package com.freshcity.page.feiji
{
	import com.freshcity.component.container.Component;
	import com.freshcity.core.GlobalVar;
	import com.freshcity.core.MainScene;
	import com.freshcity.core.OpCodes;
	import com.freshcity.feiji.FeijiInfoBack;
	import com.freshcity.lib.tooltip.ToolTipsManager;
	import com.freshcity.utils.StringUtil;
	import com.greensock.TweenMax;
	import com.pblabs.debug.Logger;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class FeiJiInfo extends Component
	{
		public var owner:FeiJiView;
		private var _feiji:*;
		private var back:FeijiInfoBack;
		private var srcUserLabel:TextField;


		public function FeiJiInfo()
		{
			super(null, 0, 0);
		}
		
		private function initPanel():void
		{
			srcUserLabel.addEventListener(TextEvent.LINK, owner.showUserDetail, false, 0, true);
			back.wordBtn.addEventListener(MouseEvent.CLICK, onWordClickHandler);
			back.yesBtn.addEventListener(MouseEvent.CLICK, onYesClick);
			back.ignoreBtn.addEventListener(MouseEvent.CLICK, onIgnoreClick);
		}
		
		private function onWordClickHandler(event:Event):void
		{
			MainScene.writeMsg.uid=owner.selectedPost.fromUser;
			MainScene.writeMsg.isReply=true;
			MainScene.writeMsg.onShow();
		}
		
		protected function onIgnoreClick(event:MouseEvent):void
		{
			setVoteBtn(false);
			main.commu.send(OpCodes.EVALUATE_FEIJI, {fid: owner.selectedPost.id,act:0});
		}
		
		public function onYesClick(event:MouseEvent=null):void
		{
			setVoteBtn(false);
			main.commu.send(OpCodes.EVALUATE_FEIJI, {fid: owner.selectedPost.id,act:1});
		}
		
		protected function onNoClick(event:MouseEvent):void
		{
			setVoteBtn(false);
			main.commu.send(OpCodes.EVALUATE_FEIJI, {fid: owner.selectedPost.id,act:2});
		}
		
		public function setVoteBtn(status:Boolean):void
		{
			//back.ignoreBtn.mouseEnabled = status;
			//back.ignoreBtn.mouseChildren = status;
			
			back.yesBtn.mouseEnabled = status;
			back.yesBtn.mouseChildren = status;
			back.wordBtn.mouseEnabled = status;
			back.wordBtn.mouseChildren = status;
		}		

		override protected function addChildren():void
		{
			super.addChildren();
			back=new FeijiInfoBack();
			back.mouseEnabled = false;
			addChild(back);
			
			var style:StyleSheet=new StyleSheet();
			style.setStyle("a:link", {color: '#0000FF', fontSize: '12'});
			style.setStyle("a:hover", {color: '#ff0000', textDecoration: 'underline', fontSize: '12'});

			srcUserLabel=back.nameLabel;
			srcUserLabel.styleSheet=style;
		}

		override public function draw():void
		{
			super.draw();
			main = owner.main;
			initPanel();
		}

		private function resort():void
		{
			back.content.text=_feiji.content;
			back.sexIcon.gotoAndStop(_feiji.sex);
			back.createdAtLabel.text = _feiji.createdAt;
			
			//var flag:Boolean = (_feiji.status!="-1");
			this.setVoteBtn(true);
			//back.flowAmt.text = feiji.flowAmt;
			srcUserLabel.htmlText="".concat("<a href='event:", String(_feiji.fromUser), "'>", "用户",_feiji.fromUser, "</a>");
			Logger.debug(this,"resort",GlobalVar.LOGIN_USER.sex+"/"+GlobalVar.LOGIN_USER.receiveFeiji);
		}
		
		public function onShow():void
		{
			if(owner.selectedPost){
				TweenMax.to(owner.searchFeiji,0.3,{autoAlpha:0});
				TweenMax.to(this,0.5,{autoAlpha:1,delay:0.3});
				TweenMax.from(back.content,0.5,{autoAlpha:0,delay:0.6,onInit:resort});
			}
		}
		
		public function onHide(callback:Function):void
		{
			TweenMax.to(back.content,0.5,{autoAlpha:0,onComplete:callback});
		}

		public function set feiji(value:*):void
		{
			_feiji=value;
		}


	}
}
